home *** CD-ROM | disk | FTP | other *** search
- /* cat > headers/plot2d.h << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* plot2d.h: header for plot2d.c file */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- #define plot2d_h 1
-
- #include "all.h"
- #include "newext.h"
-
- /*
- static int c_levels = 11;
- static int c_array[] = { 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240 };
- */
-
- /* EOF */
- /* cat > src+obj/plot2d/contour.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* contour: contour plotting */
- /* int nc -- number of contour levels */
- /* int z[] -- "nc" contour levels in */
- /* increasing order */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "plot2d.h" */
-
- void
- contour (datx, daty, datap, nc, z)
- int datx, daty, nc, z[];
- Point *datap;
-
- {
- int i, j, k, jump, dmin, dmax;
- int h0, h1, h2, h3;
- int d0, d1, d2, d3;
- float x1, y1, x2, y2;
- float xc, yc, xn, yn;
- unsigned char b[CANVAS_XSIZ];
- Point **data, pp, pv;
-
- /* Check the input parameters for validity */
- if (datx <= 0 || daty <= 0 || nc <= 0)
- return;
- for (k = 1; k < nc; k++)
- if (z[k] <= z[k - 1])
- return;
-
- /* Dynamically allocate spaces */
- data = (Point **) malloc (daty * sizeof (Point *));
- if (data == NULL)
- {
- msg_write ("Error: Contour memory allocation failed.");
- return;
- }
- data[0] = datap;
- for (j = 1; j < daty; j++)
- {
- data[j] = data[j - 1] + datx;
- }
-
- pp = data[0][0];
- pv = data[daty - 1][datx - 1];
- gfx_init ();
- hid_scale (pp.x, pv.x, pp.y, pv.y);
- win_scale (pp.x, pv.x, pp.y, pv.y);
-
- gfx_move (pp.x, pp.y);
- gfx_vector (pv.x, pp.y, 0);
- gfx_vector (pv.x, pv.y, 0);
- gfx_vector (pp.x, pv.y, 0);
- gfx_vector (pp.x, pp.y, 0);
-
- /* Scan the array, top down, left to right */
- daty--;
- datx--;
- for (j = 0; j < daty; j++)
- {
- for (i = 0; i < datx; i++)
- {
-
- d0 = data[j][i].z;
- d1 = data[j][i + 1].z;
- d2 = data[j + 1][i].z;
- d3 = data[j + 1][i + 1].z;
-
- xc = data[j][i].x;
- xn = data[j][i + 1].x;
- yc = data[j][i].y;
- yn = data[j + 1][i].y;
-
- dmax = dmin = d0;
- if (d1 < dmin)
- dmin = d1;
- if (d2 < dmin)
- dmin = d2;
- if (d3 < dmin)
- dmin = d3;
-
- if (d1 > dmax)
- dmax = d1;
- if (d2 > dmax)
- dmax = d2;
- if (d3 > dmax)
- dmax = d3;
-
- if (dmax < z[0] || dmin > z[nc - 1] || dmin == dmax)
- continue;
-
- for (k = 0; k < nc; k++)
- {
- if (z[k] < dmin || z[k] > dmax)
- continue;
-
- h0 = d0 - z[k];
- h1 = d1 - z[k];
- h2 = d2 - z[k];
- h3 = d3 - z[k];
-
- jump = 0;
- jump |= (h0 >= 0) << 3;
- jump |= (h1 >= 0) << 2;
- jump |= (h2 >= 0) << 1;
- jump |= (h3 >= 0);
-
- switch (jump)
- {
- case 0:
- case 15:
- continue;
- case 1: /* Line between sides 1-3 and 2-3 */
- case 14:
- if (!h3)
- {
- b[i] = 2;
- continue;
- }
- x1 = xn;
- y1 = (h3 * yc - h1 * yn) / (h3 - h1);
- x2 = (h3 * xc - h2 * xn) / (h3 - h2);
- y2 = yn;
- break;
- case 2: /* Line between sides 0-2 and 2-3 */
- case 13:
- if (!h2)
- {
- b[i] = 2;
- continue;
- }
- x1 = xc;
- y1 = (h2 * yc - h0 * yn) / (h2 - h0);
- x2 = (h3 * xc - h2 * xn) / (h3 - h2);
- y2 = yn;
- break;
- case 3: /* Line between sides 0-2 and 1-3 */
- case 12:
- x1 = xc;
- y1 = (h2 * yc - h0 * yn) / (h2 - h0);
- x2 = xn;
- y2 = (h3 * yc - h1 * yn) / (h3 - h1);
- break;
- case 4: /* Line between sides 0-1 and 1-3 */
- case 11:
- if (!h1)
- continue;
- x1 = (h1 * xc - h0 * xn) / (h1 - h0);
- y1 = yc;
- x2 = xn;
- y2 = (h3 * yc - h1 * yn) / (h3 - h1);
- break;
- case 5: /* Line between sides 0-1 and 2-3 */
- case 10:
- x1 = (h1 * xc - h0 * xn) / (h1 - h0);
- y1 = yc;
- x2 = (h3 * xc - h2 * xn) / (h3 - h2);
- y2 = yn;
- break;
- case 6:
- case 9:
- if (b[i] == 0)
- { /* Lines 0-1 to 1-3 and 0-2 to 2-3 */
- x1 = (h1 * xc - h0 * xn) / (h1 - h0);
- y1 = yc;
- x2 = xn;
- y2 = (h3 * yc - h1 * yn) / (h3 - h1);
- gfx_line (x1, y1, x2, y2, 0);
- x1 = xc;
- y1 = (h2 * yc - h0 * yn) / (h2 - h0);
- x2 = (h3 * xc - h2 * xn) / (h3 - h2);
- y2 = yn;
- break;
- }
- if (b[i] == 1)
- { /* Lines 0-1 to 0-2 and 1-3 to 2-3 */
- x1 = (h1 * xc - h0 * xn) / (h1 - h0);
- y1 = yc;
- x2 = xc;
- y2 = (h2 * yc - h0 * yn) / (h2 - h0);
- gfx_line (x1, y1, x2, y2, 0);
- x1 = xn;
- y1 = (h3 * yc - h1 * yn) / (h3 - h1);
- x2 = (h3 * xc - h2 * xn) / (h3 - h2);
- y2 = yn;
- break;
- }
- /* Line between sides 0-2 and 1-3 */
- x1 = xc;
- y1 = (h2 * yc - h0 * yn) / (h2 - h0);
- x2 = xn;
- y2 = (h3 * yc - h1 * yn) / (h3 - h1);
- gfx_line (x1, y1, x2, y2, 0);
- /* Line between sides 0-1 and 2-3 */
- x1 = (h1 * xc - h0 * xn) / (h1 - h0);
- y1 = yc;
- x2 = (h3 * xc - h2 * xn) / (h3 - h2);
- y2 = yn;
- break;
- case 7: /* Line between sides 0-1 and 0-2 */
- case 8:
- if (!h0)
- continue;
- x1 = (h1 * xc - h0 * xn) / (h1 - h0);
- y1 = yc;
- x2 = xc;
- y2 = (h2 * yc - h0 * yn) / (h2 - h0);
- break;
- default:
- continue;
- }
- gfx_line (x1, y1, x2, y2, 0);
-
- if (x1 > x2)
- b[i] = 1;
- else if (x1 < x2)
- b[i] = 0;
- else
- b[i] = 2;
-
- } /* end of k loop */
- } /* end of i loop */
- } /* end of j loop */
-
- free (data);
- }
- /* EOF */
- /* cat > src+obj/plot2d/plot_twod.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* plot_twod: 2-D plotting procedure */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "plot2d.h" */
-
- void
- plot_twod ()
- {
- Point *data;
- int i, j, tmp;
- int c_levels = 0, c_array[256];
- char buf[256], *str, *p;
- bool done = FALSE;
-
- int xdim = curr_image.xdim;
- int ydim = curr_image.ydim;
- int xpos = curr_image.startx;
- int ypos = curr_image.starty;
-
- int delta;
- int plevels = 10;
- char *spaces = " ";
-
- clear_plot ();
-
- strcpy (buf, (char *) panel_get_value (level_item));
- p = buf;
- while (!done)
- {
- while (*p == ' ')
- p++;
- str = p;
- while (*p != ' ' && *p != ',' && *p != '\0')
- p++;
- if (*p == '\0')
- done = TRUE;
- else
- *p++ = '\0';
-
- if (str != p)
- {
- c_array[c_levels++] = (int) atoi (str);
- }
- }
- if (c_levels == 0)
- return;
-
- for (i = c_levels - 1; i > 0; i--)
- {
- for (j = 0; j < i; j++)
- {
- if (c_array[j] > c_array[j + 1])
- {
- tmp = c_array[j];
- c_array[j] = c_array[j + 1];
- c_array[j + 1] = tmp;
- }
- }
- }
-
- sprintf (msgstr, "Note: Contour levels - ");
- msg_write(msgstr);
- for (i = 0; i < c_levels; i += plevels)
- {
- strcpy (msgstr, spaces);
- delta = (c_levels - i) < plevels ? c_levels - i : plevels;
- for (j = i; j < i + delta; j++)
- {
- sprintf (wkstr, "%d ", c_array[j]);
- strcat (msgstr, wkstr);
- }
- msg_write(msgstr);
- }
-
- tmp = (xdim + 1) >> 1;
- if ((data = (Point *) malloc (tmp * ydim * sizeof (Point))) == NULL)
- {
- msg_write ("Error: Not enough memory to hold plot data matrix.");
- return;
- }
- if (get_matrix (data, xdim, ydim, xpos, ypos) != 0)
- return;
-
- contour (tmp, ydim, data, c_levels, c_array);
- free (data);
- }
- /* EOF */
-